/**
 * 
 */

var vm = new Vue({
	el:'#firMasker',
	data:{
		showList: true,
		title: null,
		student:{
			name:null,
			gender:null,
			birthday:null,
			//身份证号码student表里面没有
			phone:null,
			webchat:null,//微信
			schoolno:null,
			grade:null//年级
			//班级student表里面没有
		},
		school:{
			schoolno:null,//学校Id
			campus:null,//学校校区
			schoolname:null//学校名称
		},
		guardian:{//监护人信息
			name:null,
			phone:null,
			//职业guardian表里面没有
			address:null,
			//所属校区在guardian表里面没有
			introducer:null,//介绍人
			duty:null,//责任人
			profession:null,//职业
			guardianno:null,//序号
			studentno:null,//学生序号
			name:null,//姓名
			birthday:null,//出生日期
			gender:null,//性别
			idtype:null,//证件类型
			idno:null,//证件号码
			relation:null,//与学生关系
			job:null,//工作
			workinfo:null,//单位
			email:null,//邮箱
			webchat:null,//微信
			address:null,//地址
			remark:null,//备注
			backup1:null,//备用1
			backup2:null,//备用2
			phone:null//联系电话
		}
	},
	methods:{
		save:function(){
			var chargeManagerVO = '{"school":'+JSON.stringify(vm.school)+',"student":'+JSON.stringify(vm.student)+',"guardian":'+JSON.stringify(vm.guardian)+'}';
			$.ajax({
				type: "POST",
			    url: baseURL + "generator/chargeManager/save",
			    contentType: "application/json; charset=utf-8",
			    dataType: "json",   
			    data: chargeManagerVO,
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		initSchool:function(){
			$.ajax({
				type: "POST",
			    url: baseURL + "generator/school/findAllSchool",
                contentType: "application/json",
			    success: function(r){
					if(r.code == 0){
						var page = r.page;
						var pageLen = page.length;
						var $school = $("#schoolno");
						$school.change(function(){
							$.ajax({
								type: "POST",
							    url: baseURL + "generator/school/findAllCampus?schoolname="+$("#schoolno").find("option:selected").text(),
				                contentType: "application/json",
							    success: function(r){
							    	if(r.code == 0){
							    		var campus = r.page;
							    		var campusLen = campus.length;
							    		var $campus = $("#campus");
							    		$campus.empty();
							    		$campus.append("<option selected=''>请选择</option>");
							    		for(var j = 0; j < campusLen; j++){
											if(j ==  0 ){
												$campus.append("<option selected='selected' value='"+campus[j].schoolno+"'>"+campus[j].campus+"</option>")
											}else{
												$campus.append("<option value='"+campus[j].schoolno+"'>"+campus[j].campus+"</option>")
											}
										}
							    	}else{
							    		alert(r.msg)
							    	}
							    }
							})
						});
						$school.empty();
						$school.append("<option selected=''>请选择</option>");
						for(var i = 0; i < pageLen; i++){
							if(i ==  0 ){
								$school.append("<option selected='selected' value='"+page[i].schoolno+"'>"+page[i].schoolname+"</option>")
							}else{
								$school.append("<option value='"+page[i].schoolno+"'>"+page[i].schoolname+"</option>")
							}
							
						}
					}else{
						alert(r.msg);
					}
				}
			});
		},
		initGrade:function(){
			$.ajax({
				type: "POST",
			    url: baseURL + "generator/grade/findAllGrade",
                contentType: "application/json",
			    success: function(r){
					if(r.code == 0){
						var page = r.page;
						var pageLen = page.length;
						var $grade = $("#grade");
						$grade.empty();
						$grade.append("<option selected='selected'>请选择</option>");
						for(var i = 0; i < pageLen; i++){
							if(i == 0){
								$grade.append("<option selected='selected' value='"+page[i].code+"'>"+page[i].name+"</option>");
							}else{
								$grade.append("<option value='"+page[i].code+"'>"+page[i].name+"</option>");
							}
							
						}
					}else{
						alert(r.msg);
					}
				}
			});
		},
		initProfession:function(){
			$.ajax({
				type: "POST",
			    url: baseURL + "generator/profession/findAllProfession",
                contentType: "application/json",
			    success: function(r){
					if(r.code == 0){
						var page = r.page;
						var pageLen = page.length;
						var $profession = $("#profession");
						$profession.empty();
						$profession.append("<option selected='selected'>请选择</option>");
						for(var i = 0; i < pageLen; i++){
							if(i == 0){
								$profession.append("<option selected='selected' value='"+page[i].code+"'>"+page[i].name+"</option>");
							}else{
								$profession.append("<option value='"+page[i].code+"'>"+page[i].name+"</option>");
							}
							
						}
					}else{
						alert(r.msg);
					}
				}
			});
		}
	},
	mounted:function(){
		this.initSchool();
		this.initGrade();
		this.initProfession();
	}
});